package com.bh.ly.oa.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.util.Log;

public class HttpClent {

	public static JSONObject getOrderJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String url=Config.domain+Config.newOderlist+java.net.URLEncoder.encode(GetJSonData.getOrderListJsonData(map),"utf-8");
			jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}
	

	public static boolean hasUnreadOrderToday() {
        long rowCount = 0;
        try {
            HashMap<String, String> map = new HashMap<String, String> ();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String today = format.format(new Date());
            map.put("startdate", today);
            map.put("enddate", today);
            String url=Config.domain+Config.newOderlist+java.net.URLEncoder.encode(GetJSonData.getOrderListJsonData(map), "utf-8");
            JSONObject jsonObject = new JSONObject(Util.getResponseBody(url)); 
            Log.d("HttpClent", "" + jsonObject);
            rowCount = jsonObject.getLong("rowCount");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rowCount > 0;
    }
	
	public static JSONObject getRelbackOrderJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String url=Config.domain+Config.listBilReturnfac+java.net.URLEncoder.encode(GetJSonData.getRelbackOrderListJsonDatat(map).toString(),"utf-8");
			jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	public static boolean hasBackOrderNoticeToday() {
        long rowCount = 0;
        try {
            HashMap<String, String> map = new HashMap<String, String> ();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String today = format.format(new Date());
            map.put("startdate", today);
            map.put("enddate", today);
            String url=Config.domain+Config.listBilReturnfac+java.net.URLEncoder.encode(GetJSonData.getBackOrderNotice(map).toString(),"utf-8");
            JSONObject jsonObject = new JSONObject(Util.getResponseBody(url));
            Log.d("HttpClent", "" + jsonObject);
            rowCount = jsonObject.getLong("rowCount");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rowCount > 0;
    }
	
	public static JSONObject getOrderDetaillistJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String url=Config.domain+Config.orderDetail+java.net.URLEncoder.encode(GetJSonData.getOrderDetailJsonData(map),"utf-8");
			jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}

	public static JSONObject getGoodsaleJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String param=GetJSonData.getGoodSaleJsonData(map);
			String url=Config.domain+Config.listGoodsSaleDept+java.net.URLEncoder.encode(param,"utf-8");
		    jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}
	
	public static JSONObject getSuppliersaleJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String param=GetJSonData.getSuppliersaleJsonData(map);
			String url=Config.domain+Config.listSupplierSaleDaily+java.net.URLEncoder.encode(param,"utf-8");
			jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}

	public static JSONObject getNoticeJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String param=GetJSonData.getAnnouncementJsonData(map);
			String url=Config.domain+Config.listAnnouncement+java.net.URLEncoder.encode(param,"utf-8");
			 jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}

	public static JSONObject getLicenseJsonData(Map map) {
		JSONObject jsonObject=null;
		try {
			String param=GetJSonData.getlicenseJsonData(map);
			String url=Config.domain+Config.listSupplierCertificate+java.net.URLEncoder.encode(param,"utf-8");
			jsonObject = new JSONObject(Util.getResponseBody(url)); 
			//jsArray= jsonObject.getJSONArray("dataList").length()<1?new JSONArray():jsonObject.getJSONArray("dataList");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonObject;
	}
}
